package cn.gxj62;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class deleteStudent extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String[] selectedStudentIds = request.getParameterValues("bin"); // Assuming the checkbox name is checkboxName
        response.setContentType("text/html");
        if (selectedStudentIds != null) {
            for (String id : selectedStudentIds) {
                mysql.deleteStudentById(Integer.parseInt(id));
            }
            response.getWriter().println("删除成功<br /><a href=\"javascript:history.back(-1)\">返回上一页</a>");
        } else {
            response.getWriter().println("没有学生被删除<br /><a href=\"javascript:history.back(-1)\">返回上一页</a>");
        }
    }
}
